function ruleArgs(iQuantity, fEffort, bSameSite, sObjective, sDescription)
{
var args = new Object();

args.iQuantity = iQuantity;
args.fEffort = fEffort;
args.bSameSite = bSameSite;
args.sObjective = sObjective;
args.sDescription = sDescription;

return args;
}

var OBJECTIVE_RANDOM_ID = "0";
var OBJECTIVE_LEAST_BUSY_ID = "1";
var OBJECTIVE_MOST_BUSY_ID = "2";
var OBJECTIVE_CUSTOM_ID = "3";

var OBJECTIVE_RANDOM_EXPRESSION =
"<Expression><Body>udf \"Random\"(factory,resource,appointment,request,leftoffset,rightoffset)</Body>" +
"<Parameters><Parameter name=\"factory\"/><Parameter name=\"resource\"/><Parameter name=\"appointment\"/><Parameter name=\"request\"/><Parameter name=\"leftoffset\"/><Parameter name=\"rightoffset\"/></Parameters>" +
"<Properties EvaluationInterval=\"P0D\" evaluationcost=\"0\"/></Expression>";
var OBJECTIVE_LEAST_BUSY_EXPRESSION =
"<Expression><Body>udf \"LeastBusy\"(factory,resource,appointment,request,leftoffset,rightoffset)</Body>" +
"<Parameters><Parameter name=\"factory\"/><Parameter name=\"resource\"/><Parameter name=\"appointment\"/><Parameter name=\"request\"/><Parameter name=\"leftoffset\"/><Parameter name=\"rightoffset\"/></Parameters>" +
"<Properties EvaluationInterval=\"P1D\" evaluationcost=\"1\"/></Expression>";
var OBJECTIVE_MOST_BUSY_EXPRESSION =
"<Expression><Body>udf \"MostBusy\"(factory,resource,appointment,request,leftoffset,rightoffset)</Body>" +
"<Parameters><Parameter name=\"factory\"/><Parameter name=\"resource\"/><Parameter name=\"appointment\"/><Parameter name=\"request\"/><Parameter name=\"leftoffset\"/><Parameter name=\"rightoffset\"/></Parameters>" +
"<Properties EvaluationInterval=\"P1D\" evaluationcost=\"1\"/></Expression>";


var ADVANCED_SECTION_HEIGHT = 60;

var	DEFAULT_QUANTITY = "1";
var DEFAULT_EFFORT = "1";
var DEFAULT_SAMESITE = "1";
var DEFAULT_OBJECTIVE = OBJECTIVE_RANDOM_EXPRESSION;

var _oCurrentTree = null;

function convertIdToExpression(iId)
{
switch (iId)
{
case OBJECTIVE_MOST_BUSY_ID:
return OBJECTIVE_MOST_BUSY_EXPRESSION;
case OBJECTIVE_LEAST_BUSY_ID:
return OBJECTIVE_LEAST_BUSY_EXPRESSION;
case OBJECTIVE_RANDOM_ID:
return OBJECTIVE_RANDOM_EXPRESSION;
default:
return "";
}
}

function convertExpressionToId(sExpression)
{
switch (sExpression)
{
case OBJECTIVE_MOST_BUSY_EXPRESSION:
return OBJECTIVE_MOST_BUSY_ID;
case OBJECTIVE_LEAST_BUSY_EXPRESSION:
return OBJECTIVE_LEAST_BUSY_ID;
case OBJECTIVE_RANDOM_EXPRESSION:
return OBJECTIVE_RANDOM_ID;
default:
return OBJECTIVE_CUSTOM_ID;
}
}

function makeLink(innerText, action)
{
return "<span onclick=\"" + action + "\" class=\"rsHelperlink\">" + innerText + "</span>";
}

function makeTag(sTagname, sInnerText, sAttributes)
{
return (sInnerText == null) ?
formatString("<{0}/>", sTagname) :
formatString("<{0}{1}>{2}</{0}>", sTagname,
(sAttributes != null && sAttributes.length > 0)? (" " + sAttributes) : "",
sInnerText);
}






function loadResourceSpecTree(oTree, commandName, resourceSpecId, bLoadAsync)
{
if (resourceSpecId != "")
{

var oCommand = new RemoteCommand("ResourceSpecTree", commandName);
if (oCommand != null)
{
oCommand.SetParameter("id", resourceSpecId);


_oCurrentTree = oTree;


if (bLoadAsync)
{

oCommand.Execute(TreeLoaded);
}
else
{

TreeLoaded(oCommand.Execute());
}
}
}
else
{
var sMemberXml = getStartTemplate();
SetupTree(sMemberXml, oTree);
}
}

function TreeLoaded(oResult)
{

var sMemberXml = "<tree></tree>";

if (oResult.Success)
{

var xmlNode = oResult.Xml;
if (xmlNode)
{

var oResultContents = xmlNode.selectSingleNode("resourcespec");
if (oResultContents !== null)
{

sMemberXml = '<tree>' +
oResultContents.xml +
'</tree>';
}
}
}

SetupTree(sMemberXml, _oCurrentTree);
}

function SetupTree(sMemberXml, oTree)
{

if (oTree.Count != null)
{

registerNodeTypes(oTree);


oTree.Xml = sMemberXml;


setUaLabels(oTree);

oTree.RenderTree();
}
}
